//
//  GrabBillPageViewController.m
//  dangdang
//
//  Created by air on 16/2/2.
//  Copyright © 2016年 luweijie. All rights reserved.
//

#import "GrabBillPageViewController.h"

@interface GrabBillPageViewController ()

@end

@implementation GrabBillPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (![_navi isEqualToString:@"navi"]) {
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消订单" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)cancel{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"取消订单需要与客户协商，是否确认取消订单?" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        dispatch_async(dispatch_get_main_queue(), ^{
            
            NSString * token = userObject.accessToken;
            NSString * userIDString = userObject.userID;
            NSString * orderIDString = userObject.ordID;
            
            NSMutableDictionary *params = [[NSMutableDictionary alloc]init];
            [params setObject:token forKey:@"token"];
            [params setObject:userIDString forKey:@"uid"];
            [params setObject:orderIDString forKey:@"order_id"];
            
            [self postRequestWithMethodName:@"order/cancel_order" andParams:params andSender:nil];
        });
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        dispatch_async(dispatch_get_main_queue(), ^{
            
        });
    }];
    [alertVC addAction:action];
    [alertVC addAction:cancelAction];
    [self presentViewController:alertVC animated:YES completion:nil];
}

//网络连接返回数据
- (void)requestSuccessedWithResult:(id)result NSURLSessionTask:(NSURLSessionTask *)task sender:(id)sender{
    
    if ([result isKindOfClass:[NSDictionary class]]) {
        NSString * code = [NSString stringWithFormat:@"%@", [result objectForKey:@"retcode"]];
        if ([code isEqualToString:@"0"]){
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
